package com.example.api;

import jakarta.servlet.ServletContext;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ws
 * Date: 2024-03-02
 * Time: 16:20
 *
 * 使用原始对象
 */

@Controller
public class ApiController {

    // 下面的这些对象都可以自动获取

    /*
    ServletContext 的作用
    1. 配置文件
    2. 全局最大的共享域
    3. 核心 api getRealPath
     */
    @Autowired
    private ServletContext servletContext; // 1. 直接从容器中获取

    public void data(HttpServletResponse response, // 这些对象也是自动给注入
                     HttpServletRequest request,
                     HttpSession session) {

        // 2. 通过 request 和 session 获取
        ServletContext servletContext1 = request.getServletContext();
        ServletContext servletContext2 = session.getServletContext();

    }
}
